//
//  TestMKUIListViewSectionHeadFootView.m
//  MKUITestApp
//
//  Created by 苏尚进 on 2023/11/11.
//  Copyright © 2023 moon. All rights reserved.
//

#import "TestMKUIListViewSectionHeadFootView.h"

@interface TestMKUIListViewSectionHeadFootView()
@property(nonatomic,strong) MKUIFlowLayoutConstraint *flowlayout;
@end

@implementation TestMKUIListViewSectionHeadFootView
- (id)initWithFrame:(CGRect)frame{
    if(self=[super initWithFrame:frame]){
        self.layer.borderWidth = 1;
        self.layer.borderColor = UIColor.mk_listViewSeparatorColor.CGColor;
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.numberOfLines = 2;
        self.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:self.titleLabel];
        self.flowlayout = [[MKUIFlowLayoutConstraint alloc] initWithItems:@[self.titleLabel] constraintParam:(MKUIFlowLayoutConstraintParam_H_C_L) contentInsets:MKUIEdgeInsetsMakeSameEdge(10) interitemSpacing:10];
    }
    return self;
}
- (void)setTitle:(NSString *)title{
    if(_title==title||[_title isEqualToString:title])return;
    _title = title;
    self.titleLabel.text = title;
    [self setNeedsLayout];
}
- (void)layoutSubviews{
    [super layoutSubviews];
    CGRect bounds = self.contentView.bounds;
    self.flowlayout.bounds = bounds;
    [self.flowlayout layoutItemsWithResizeItems:YES];
}
- (CGSize)sizeThatFits:(CGSize)size{
    return [self.flowlayout sizeThatFits:size resizeItems:YES];
}
+ (TestMKUIListViewSectionHeadFootView *)sectionViewWithTitle:(NSString *)title{
    TestMKUIListViewSectionHeadFootView *view = [[self alloc] init];
    view.title = title;
    return view;
}
@end
